package com.xbongbong.workflow.model.impl;

import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.workflow.domain.dao.WorkflowTransferDataDao;
import com.xbongbong.workflow.domain.entity.WorkflowTransferDataEntity;
import com.xbongbong.workflow.model.WorkflowTransferDataModel;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 */
@Service("workflowTransferDataModel")
public class WorkflowTransferDataModelImpl implements WorkflowTransferDataModel {
    @Resource
    private WorkflowTransferDataDao workflowTransferDataDao;

    @Override
    public Long insert(WorkflowTransferDataEntity entity) {
        long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return workflowTransferDataDao.insert(entity);
    }

    @Override
    public void insertBatch(List<WorkflowTransferDataEntity> list) {
        workflowTransferDataDao.insertBatch(list);
    }

    @Override
    public List<WorkflowTransferDataEntity> findEntities(Map<String, Object> param) {
        return workflowTransferDataDao.findEntities(param);
    }

    @Override
    public Integer getEntityCount(Map<String, Object> param) {
        return workflowTransferDataDao.getEntitiesCount(param);
    }

    @Override
    public void update(WorkflowTransferDataEntity entity) {
        entity.setUpdateTime(DateTimeUtil.getInt());
        workflowTransferDataDao.update(entity);
    }

    @Override
    public WorkflowTransferDataEntity getByKey(Long key, String corpid) {
        return workflowTransferDataDao.getByKey(key, corpid);
    }

    @Override
    public WorkflowTransferDataEntity getByTaskId(Long taskId, String corpid) {
        return workflowTransferDataDao.getByTaskId(taskId, corpid);
    }

    @Override
    public void deleteByTaskId(Long taskId, String corpid) {
        workflowTransferDataDao.deleteByTaskId(taskId, corpid);
    }

    @Override
    public void deleteByTaskIds(String corpid, List<Long> taskIds) {
        workflowTransferDataDao.deleteByTaskIds(corpid, taskIds);
    }

    @Override
    public List<WorkflowTransferDataEntity> hasDataInApprovalWithData(Map<String, Object> param) {
        return workflowTransferDataDao.hasDataInApprovalWithData(param);
    }

    @Override
    public Integer updateDataBatch(List<WorkflowTransferDataEntity> list, String corpid) {
        if (CollectionUtils.isEmpty(list)) {
            return 0;
        }
        return workflowTransferDataDao.updateDataBatch(list, corpid);
    }
}
